package com.woniu.zsd.recycle.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniu.zsd.common.util.JWTUtil;
import com.woniu.zsd.common.util.Result;
import com.woniu.zsd.recycle.dto.UserSelectPriceDto;
import com.woniu.zsd.recycle.dto.WastePricingBySiteIdDto;
import com.woniu.zsd.recycle.form.StationPriceForm;
import com.woniu.zsd.recycle.form.WasteStationPriceForm;
import com.woniu.zsd.recycle.model.WastePricing;
import com.woniu.zsd.recycle.param.StationPriceParam;
import com.woniu.zsd.recycle.param.WasteStationPriceParam;
import com.woniu.zsd.recycle.service.WastePricingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 彭于晏
 * @since 2025年02月18日
 */
@RestController
@RequestMapping("/wastePricing")
@Api(tags = "废品价格管理")
public class WastePricingController {
    @Resource
    private WastePricingService wastePricingService;
    @PostMapping("/stationPrice")
    @ApiOperation(value = "站点对废品定价")
    public Result StationPrice(@RequestBody StationPriceForm form)throws Exception{
        wastePricingService.StationPrice(BeanUtil.toBean(form, StationPriceParam.class));
        return Result.success("站点对废品定价成功",null);
    }
    @PostMapping("/selectStationPriceBySiteId")
    @ApiOperation(value = "根据站点ID查询站点对所有废品定价")
    public Result selectStationPriceBySiteId(Integer siteId)throws Exception{
        System.out.println("siteId:"+siteId );
        List<WastePricingBySiteIdDto> dtos=wastePricingService.selectStationPriceBySiteId(siteId);
        return Result.success("根据站点ID查询站点对废品定价成功",dtos);
    }
    @PostMapping("/selectPriceByTypeId")
    @ApiOperation(value = "根据废品类型ID查询所有站点对该类型废品定价")
    public Result selectPriceByTypeId(String typeName)throws Exception{
        List<WastePricingBySiteIdDto> dtos=wastePricingService.selectPriceByTypeId(typeName);
        return Result.success("根据废品类型ID查询站点对该废品定价成功",dtos);
    }
    @PostMapping("/wasteStationPrice")
    @ApiOperation(value = "平台对废品定参考价格")
    public Result wasteStationPrice(@RequestBody WasteStationPriceForm form)throws Exception{
        wastePricingService.wasteStationPrice(BeanUtil.toBean(form, WasteStationPriceParam.class));
        return Result.success("平台对废品定参考价格成功",null);
    }
    @GetMapping("/userSelectPrice")
    @ApiOperation(value = "查询平台对废品定参考价格")
    public Result userSelectPrice()throws Exception{
        List<UserSelectPriceDto> dtos = wastePricingService.userSelectPrice();
        return Result.success("用户查询平台对废品定参考价格成功",dtos);
    }
    @PostMapping ("/updatePriceByStationId")
    @ApiOperation(value = "用户查询平台对废品定参考价格")
    public Result updatePriceByStationId(@RequestParam("stationId") Integer stationId)throws Exception{
        wastePricingService.updatePriceByStationId(stationId);
        return Result.success("用户查询平台对废品定参考价格成功",null);
    }
}

